home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / src / dumptext.c < prev    next >
Text File  |  1993-12-06  |  6KB  |  191 lines

  1. /**
  2.  ** DUMPTEXT.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "grx.h"
  25. #include "libgrx.h"
  26. #include "grxfont.h"
  27. #include "clipping.h"
  28.  
  29. #define  FAST    0x04
  30.  
  31. void GrDumpText(int col,int row,int wdt,int hgt,GrTextRegion *r)
  32. {
  33.     GrFont *f = CHECK_FONT(r->txr_font);
  34.     GrColorTableP fgcp,bgcp;
  35.     char *ptr,*bpt;
  36.     int xtmp,ytmp;
  37.     int xpos,ypos;
  38.     int chrw,chrh;
  39.     int fgc,bgc;
  40.     int offs,size;
  41.     int minc,maxc;
  42.     int type,attr;
  43.     int xchr,chr;
  44.     int chrsize;
  45.     int underline = 0;
  46.     int fast;
  47.     MOUSE_FLAG;
  48.  
  49.     if((f == NULL) || !f->fnt_isfixed) return;
  50.     if((col >= r->txr_width) || (row >= r->txr_height)) return;
  51.     if(col < 0) { wdt += col; col = 0; }
  52.     if(row < 0) { hgt += row; row = 0; }
  53.     if(wdt > (r->txr_width  - col)) wdt = r->txr_width  - col;
  54.     if(hgt > (r->txr_height - row)) hgt = r->txr_height - col;
  55.     if((wdt <= 0) || (hgt <= 0)) return;
  56.     chrw = f->fnt_width;
  57.     chrh = f->fnt_height;
  58.     xpos = r->txr_xpos + (chrw * col);
  59.     ypos = r->txr_ypos + (chrh * row);
  60.     xtmp = xpos + (chrw * wdt) - 1;
  61.     ytmp = ypos + (chrh * hgt) - 1;
  62.     if((xpos > _GrHiX) || (xtmp <= _GrLoX)) return;
  63.     if((ypos > _GrHiY) || (ytmp <= _GrLoY)) return;
  64.     while(xpos < _GrLoX) { if(--wdt == 0) return; xpos += chrw; col++; }
  65.     while(ypos < _GrLoY) { if(--hgt == 0) return; ypos += chrh; row++; }
  66.     while(xtmp > _GrHiX) { if(--wdt == 0) return; xtmp -= chrw; }
  67.     while(ytmp > _GrHiY) { if(--hgt == 0) return; ytmp -= chrh; }
  68.     type = r->txr_chrtype;
  69.     fast = (r->txr_backup != NULL) ? FAST : 0;
  70.     switch(type) {
  71.       case GR_WORD_TEXT:
  72.         size = sizeof(short);
  73.         fgc  = r->txr_fgcolor.v;
  74.         bgc  = r->txr_bgcolor.v;
  75.         if(fgc & GR_UNDERLINE_TEXT) {
  76.         underline = f->fnt_undwidth;
  77.         fgc &= ~GR_UNDERLINE_TEXT;
  78.         }
  79.         break;
  80.       case GR_ATTR_TEXT:
  81.         attr = (-1);
  82.         size = sizeof(short);
  83.         fgcp = r->txr_fgcolor.p;
  84.         bgcp = r->txr_bgcolor.p;
  85.         break;
  86.       default:
  87.         size = sizeof(char);
  88.         fgc  = r->txr_fgcolor.v;
  89.         bgc  = r->txr_bgcolor.v;
  90.         if(fgc & GR_UNDERLINE_TEXT) {
  91.         underline = f->fnt_undwidth;
  92.         fgc &= ~GR_UNDERLINE_TEXT;
  93.         }
  94.         break;
  95.     }
  96.     offs = (row * r->txr_lineoffset) + (col * size);
  97.     ptr  = r->txr_buffer + offs;
  98.     bpt  = r->txr_backup + offs;
  99.     offs = r->txr_lineoffset - (wdt * size);
  100.     minc = f->fnt_minchar;
  101.     maxc = f->fnt_maxchar;
  102.     chrsize = FFP(f)->ff_chrsize;
  103.     MOUSE_BLOCK(CURC,
  104.         xpos,ypos,
  105.         (xpos + (chrw * wdt) - 1),
  106.         (ypos + (chrh * hgt) - 1)
  107.     );
  108.     for( ; --hgt >= 0; ypos += chrh,ptr += offs,bpt += offs) {
  109.         xtmp = xpos;
  110.         ytmp = wdt;
  111.         for( ; --ytmp >= 0; xtmp += chrw,ptr += size,bpt += size) {
  112.         switch(type) {
  113.           case GR_WORD_TEXT:
  114.             chr = *((unsigned short *)ptr);
  115.             if(!fast) break;
  116.             if(chr == *((unsigned short *)bpt)) continue;
  117.             *((unsigned short *)bpt) = chr;
  118.             if(chr == ' ') chr = (-1);
  119.             break;
  120.           case GR_ATTR_TEXT:
  121.             xchr = *((unsigned short *)ptr);
  122.             if(fast && (xchr == *((unsigned short *)bpt))) continue;
  123.             chr = xchr & 0xff;
  124.             if(attr != (xchr &= 0xff00)) {
  125.             fgc  = (xchr >> 8)  & 0x0f;
  126.             bgc  = (xchr >> 12) & 0x07;
  127.             fgc  = GR_CTABLE_COLOR(fgcp,fgc);
  128.             bgc  = GR_CTABLE_COLOR(bgcp,bgc);
  129.             underline = (xchr & 0x8000) ? f->fnt_undwidth : 0;
  130.             attr = xchr;
  131.             }
  132.             if(fast && (chr == ' ')) chr = (-1);
  133.             break;
  134.           default:
  135.             chr = *((unsigned char *)ptr);
  136.             if(!fast) break;
  137.             if(chr == *((unsigned char *)bpt)) continue;
  138.             *((unsigned char *)bpt) = chr;
  139.             if(chr == ' ') chr = (-1);
  140.             break;
  141.         }
  142.         if((chr > maxc) || ((chr -= minc) < 0)) {
  143.             _GrSetPixBlock(PIXEL_ADDR(xtmp,ypos),
  144.             bgc,
  145.             chrw,(chrh - underline)
  146.             );
  147.         }
  148.         else {
  149.             _GrDrawChar(PIXEL_ADDR(xtmp,ypos),
  150.             chrw,(chrh - underline),
  151.             FFP(f)->ff_bits + (chr * chrsize),
  152.             fgc,bgc
  153.             );
  154.         }
  155.         if(underline > 0) {
  156.             _GrSetPixBlock(PIXEL_ADDR(xtmp,(ypos + chrh - underline)),
  157.             fgc,
  158.             chrw,underline
  159.             );
  160.         }
  161.         }
  162.     }
  163.     MOUSE_UNBLOCK();
  164. }
  165.  
  166. void GrDumpTextRegion(GrTextRegion *r)
  167. {
  168.     GrDumpText(0,0,r->txr_width,r->txr_height,r);
  169. }
  170.  
  171. void GrDumpChar(int chr,int col,int row,GrTextRegion *r)
  172. {
  173.     register int offs;
  174.  
  175.     if((col < 0) || (col >= r->txr_width))  return;
  176.     if((row < 0) || (row >= r->txr_height)) return;
  177.     switch(r->txr_chrtype) {
  178.       case GR_WORD_TEXT:
  179.       case GR_ATTR_TEXT:
  180.         offs = (row * r->txr_lineoffset) + (col * sizeof(short));
  181.         *((short *)(r->txr_buffer + offs)) = chr;
  182.         break;
  183.       default:
  184.         offs = (row * r->txr_lineoffset) + (col * sizeof(char));
  185.         *((char *)(r->txr_buffer + offs)) = chr;
  186.         break;
  187.     }
  188.     GrDumpText(col,row,1,1,r);
  189. }
  190.  
  191.